// 1. React核心库
import React from 'react';

// 2. UI组件库 - 按字母顺序
import { Descriptions, Button, Space } from 'antd';

// 3. 图标库
import { MessageOutlined } from '@ant-design/icons';

// 5. 工具库
import dayjs from 'dayjs';

// 8. 生成的类型定义 (必须使用，禁止手工定义)
import type { UserFavorite } from '@/services/generated';

interface FavoriteDetailProps {
  favorite: UserFavorite | null;
  onGoToConversation?: (conversationId: number) => void;
}

const FavoriteDetail: React.FC<FavoriteDetailProps> = ({
  favorite,
  onGoToConversation,
}) => {
  if (!favorite) {
    return <div>暂无数据</div>;
  }

  return (
    <div>
      <Descriptions column={2} bordered>
        <Descriptions.Item label="ID">{favorite.id}</Descriptions.Item>
        <Descriptions.Item label="收藏标题">{favorite.title}</Descriptions.Item>
        
        <Descriptions.Item label="关联对话ID">{favorite.conversation}</Descriptions.Item>
        <Descriptions.Item label="对话标题">{favorite.conversation_title || '未知'}</Descriptions.Item>
        
        <Descriptions.Item label="收藏时间">
          {dayjs(favorite.created_at).format('YYYY-MM-DD HH:mm:ss')}
        </Descriptions.Item>
        
        <Descriptions.Item label="更新时间">
          {dayjs(favorite.updated_at).format('YYYY-MM-DD HH:mm:ss')}
        </Descriptions.Item>
      </Descriptions>

      {favorite.note && (
        <div style={{ marginTop: 16 }}>
          <h4>备注：</h4>
          <div style={{
            backgroundColor: '#f5f5f5',
            padding: '12px',
            borderRadius: '6px',
            whiteSpace: 'pre-wrap',
            fontSize: '14px',
            lineHeight: '1.6',
            marginBottom: '12px'
          }}>
            {favorite.note}
          </div>
        </div>
      )}

      <div style={{ marginTop: 16 }}>
        <Space>
          <Button 
            type="primary"
            icon={<MessageOutlined />}
            onClick={() => onGoToConversation?.(favorite.conversation!)}
          >
            查看对话
          </Button>
        </Space>
      </div>
    </div>
  );
};

export default FavoriteDetail;